package com.atguigu.gmall.seckill.rpc;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.activity.SeckillGoods;
import com.atguigu.gmall.model.order.OrderInfo;
import com.atguigu.gmall.seckill.biz.LocalCache;
import com.atguigu.gmall.seckill.service.SecKillService;
import com.atguigu.gmall.seckill.service.SeckillGoodsService;
import org.simpleframework.xml.Order;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * @author A
 * @version 1.0
 * @description: TODO
 * @date 2024/10/18 4:31
 */
@RestController
@RequestMapping("/rpc/inner/seckill")
public class SecKillRpcController {
    @Autowired
    LocalCache localCache;
    @Autowired
    SecKillService secKillService;

    @PostMapping("/seckilllist")
    public Result<List<SeckillGoods>> getSecKillList() {
        //直接从本地缓存拿
        List<SeckillGoods> allSeckillGoods = localCache.getAllSeckillGoods();
        return Result.ok(allSeckillGoods);
    }

    //获得指定skuId的商品详情
    @GetMapping("/secKillDetails/{skuId}")
    public Result<SeckillGoods> getSecKillDetails(@PathVariable("skuId") Long skuId) {
        //直接从本地缓存拿
        SeckillGoods seckillGoodsDetail = localCache.getSeckillGoodsDetail(skuId);
        return Result.ok(seckillGoodsDetail);
    }

    @GetMapping("/orderInfo")
    public Result<OrderInfo> getSecKillOrderInfoFromRedis(@RequestParam("skuId") Long skuId) {
        OrderInfo orderInfo = secKillService.getSecKillOrderInfoFromRedis(skuId);
        return Result.ok(orderInfo);
    }
}
